using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestGSA
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            GSALib.GSA.Query q = new GSALib.GSA.Query();

            q.setSiteCollections(new string[] { "albert_collection" });

            q.setFrontend("albert_frontend");

            q.setOutputFormat(GSALib.Constants.Output.XML_NO_DTD);

            q.setOutputEncoding(GSALib.Constants.Encoding.UTF8);

            q.setAccess(GSALib.Constants.Access.PUBLIC);

            q.setMaxResults(15);
            q.setRC(true);

            GSALib.GSA.QueryTerm term = new GSALib.GSA.QueryTerm("rio");

            //term.addFileType("pdf", true);  // Only pdf files

            q.setQueryTerm(term);

            GSALib.GSA.ClientAccess ca = new GSALib.GSA.ClientAccess();

            //ca.credentails = new System.Net.NetworkCredential("", "", "");  //Use only for secure and ALL access modes

            string Value = q.getValue();

            string Url = ca.GetFullPath(Value + "&proxystylesheet=default_frontend");   //For HTML View
            //string Url = ca.GetFullPath(Value); //For XML View

            textBox1.Text = Url;
            webBrowser1.Navigate(new Uri(Url));           

            try
            {
                GSALib.GSA.Response res = ca.getGSAResponse(q, null);
                //System.Collections.ArrayList list = res.getResults();
                //foreach (GSALib.GSA.Result resf in list)
                //{
                //    string t = "";
                //}
                //GSALib.GSA.Response res = ca.getGSAResponse(q, @"C:\GSA.xml"); //For Saving Output in XML
            }
            catch (GSALib.Exceptions.GSANeedNetworkCredentailsException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}